﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using YiSha.Business.Business;
using YiSha.Entity.Business;
using YiSha.Model.Param.Business;
using YiSha.Util;
using YiSha.Util.Model;

namespace YiSha.Admin.Web.Controllers
{
    public class TreatmentController : BaseController
    {

        private TreatmentBLL treatmentBLL = new TreatmentBLL();


        #region 视图功能


        [AuthorizeFilter("business:treatment:view")]
        public IActionResult treatmentIndex()
        {
            return View();
        }

        /// <summary>
        /// 处方选择方案
        /// </summary>
        /// <returns></returns>
        public IActionResult treatmentList()
        {
            return View();
        }



        public IActionResult treatmentForm()
        {
            return View();
        }

        #endregion
                       
        #region 获取数据
        [HttpGet]
        [AuthorizeFilter("business:treatment:search,business:treatment:view")]
        public async Task<IActionResult> GetListJson(TreatmentParam param)
        {
            TData<List<TreatmentEntity>> obj = await treatmentBLL.GetList(param);
            return Json(obj);
        }

        [HttpGet]
        [AuthorizeFilter("business:treatment:search,business:treatment:view")]
        public async Task<IActionResult> GetPageListJson(TreatmentParam param, Pagination pagination)
        {
            TData<List<TreatmentEntity>> obj = await treatmentBLL.GetPageList(param, pagination);
            return Json(obj);
        }


        [HttpGet]
        public async Task<IActionResult> GetPageListJsonNoAuthority(TreatmentParam param, Pagination pagination)
        {
            TData<List<TreatmentEntity>> obj = await treatmentBLL.GetPageList(param, pagination);
            return Json(obj);
        }

        [HttpGet]
        public async Task<IActionResult> GetFormJson(long id)
        {
            TData<TreatmentEntity> obj = await treatmentBLL.GetEntity(id);
            return Json(obj);
        }

     

        [HttpGet]
        public async Task<IActionResult> GetTreatmentName(TreatmentParam param)
        {
            TData<string> obj = new TData<string>();
            var list = await treatmentBLL.GetList(param);
            if (list.Tag == 1)
            {
                obj.Data = string.Join(",", list.Data.Select(p => p.Title));
                obj.Tag = 1;
            }
            return Json(obj);
        }
        #endregion


        #region 提交数据
        [HttpPost]
        [AuthorizeFilter("business:treatment:add,business:treatment:edit")]
        public async Task<IActionResult> SaveFormJson(TreatmentEntity entity)
        {
            TData<string> obj = await treatmentBLL.SaveForm(entity);
            return Json(obj);
        }

        [HttpPost]
        [AuthorizeFilter("business:treatment:delete")]
        public async Task<IActionResult> DeleteFormJson(string ids)
        {
            TData obj = await treatmentBLL.DeleteForm(ids);
            return Json(obj);
        }
        #endregion





    }
}
